package com.qyhl.webtv.commonlib.utils.view.video.detailvideo;

import android.annotation.SuppressLint;
import android.app.Activity;

import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer;

import java.lang.reflect.Field;

public class MOrientationUtils extends OrientationUtils {


    public MOrientationUtils(Activity activity, GSYBaseVideoPlayer gsyVideoPlayer) {
        super(activity, gsyVideoPlayer);
    }

    @SuppressLint("WrongConstant")
    @Override
    public void resolveByClick() {
        Class<? extends MOrientationUtils> aClass = this.getClass();
        try {

            Field mClick = aClass.getDeclaredField("mClick");
            mClick.setAccessible(true);
            mClick.set(this, true);

            Field fmIsLand = aClass.getDeclaredField("mIsLand");
            fmIsLand.setAccessible(true);
            int mIsLand = (int) fmIsLand.get(this);


            Field screenType = aClass.getDeclaredField("screenType");
            screenType.setAccessible(true);

            Field fgsyVideoPlayer = aClass.getDeclaredField("gsyVideoPlayer");
            GSYBaseVideoPlayer gsyVideoPlayer = (GSYBaseVideoPlayer) fgsyVideoPlayer.get(this);
            screenType.set(this, mIsLand);

            if (mIsLand == 0) {
                gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getShrinkImageRes());
                fmIsLand.set(this, 1);
                Field mClickLand = aClass.getDeclaredField("mClickLand");
                mClickLand.setAccessible(true);
                mClickLand.set(this, false);
            } else {
                if (gsyVideoPlayer.isIfCurrentIsFullscreen()) {
                    gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getShrinkImageRes());
                } else {
                    gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getEnlargeImageRes());
                }
                fmIsLand.set(this, 0);
                Field mClickPort = aClass.getDeclaredField("mClickPort");
                mClickPort.setAccessible(true);
                mClickPort.set(this, false);
            }


        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }
}
